package com.exsun.ex1077.ui.fragment.vehicleinfo

import androidx.databinding.ObservableField
import androidx.lifecycle.MutableLiveData
import com.alibaba.fastjson.JSONObject
import com.exsun.ex1077.network.apiService
import com.exsun.ex1077.network.entity.MapVehicle
import com.exsun.ex1077.network.entity.MapVehicleGps
import com.exsun.ex1077.network.entity.Mileage
import com.exsun.ex1077.network.entity.MileageRank
import com.zhangping.fastjetpack.base.BaseViewModel
import com.zhangping.fastjetpack.extend.*
import com.zhangping.fastjetpack.extend.base.ResultState
import com.zhangping.fastjetpack.extend.base.request
import com.zhangping.fastjetpack.extend.databind.IntObservableField
import com.zhangping.fastjetpack.extend.databind.StringObservableField
import java.util.*

/**
 * 描述：
 * 作者：ZhangPing
 * 创建时间：2022/8/10 10:53
 */
class VehicleInfoViewModel: BaseViewModel() {

    val model = ObservableField<MapVehicle>()
    val startTime = StringObservableField("")
    val endTime = StringObservableField("")
    var mileageList: List<Mileage>? = null

    val mileageResult = MutableLiveData<ResultState<List<Mileage>?>>()
    val mapVehicleGpsResult = MutableLiveData<ResultState<MapVehicleGps?>>()

    fun loadMileageData(startTime: String, endTime: String){
        val queryMap = JSONObject().apply {
            put("dvo", model.get()?.dvo ?: "")
            put("startTime", startTime)
            put("endTime", endTime)
        }
        request({ apiService.vehicleMileage(queryMap)}, mileageResult, true)
    }

    fun loadVehicleData(){
        request({ apiService.mapVehicleGps(model.get()?.dvo ?: "")}, mapVehicleGpsResult)
    }

}